<template>
<span :class="wrapper_name">
<!--WU_TR|仓库绑定,ADD_STOCK|添加TR商品  -->
  <button v-if="col.btns.WU_TR" class="ui button primary mini" @click.stop.prevent="WU_TR(col.val)" title="仓库绑定">
    {{col.btns.WU_TR}}
  </button>
  <button v-if="col.btns.ADD_STOCK" class="ui button primary mini" @click.stop.prevent="ADD_STOCK(col.val)" title="添加TR商品">
	{{col.btns.ADD_STOCK}}
  </button>
</span>
</template>
<script type="text/ecmascript-6">
import tool from 'src/util/tool';
import util from '_util/index';
import logic from '_logic';
export default {
    data() {
        return {}
    },
    methods: {
		ADD_STOCK(id){
			let _this = this;
			util.http.getDataCom(_this, '/index/Get/get_whuse', {
				hotel_id:id
			},(rs) => {
				let warehouse_id = rs[0].warehouse_id || '';
				util.store.push(_this, 'set_in_modal','in_modal',false,true,'global');
				this.$store.state.global.eventVue.$emit('showPopCom', {
					_this: this,
					id: id,
					data: {
						fn: {
							sure: function(data) {
								let param = {
									hotel_id: id,
									warehouse_top_product_ids:JSON.parse(data.id).toString()
								};
								util.http.SR(_this, '/index/Product/addStock', param, '添加成功', (rs) => {
									logic.list.refreshListData(_this);
								});
							}
						},
						field: {
							bindModel: 107,
							bind_type: 1,
							title: '添加商品至场景',
							name: 'top_product_name',
							bind_param:`warehouse_id=${warehouse_id}`,
							search_field:'top_product_name'
						}
					},
					hide_in_model:true,
					name: 'Jbind'
				});
			})

		},
		WU_TR(id){
			let _this = this;
		util.http.getDataCom(_this, '/index/Get/get_whuse', {
			hotel_id:id
		},(rs) => {
				let warehouse_id = '',warehouse_name = '';
				if(rs[0]){
					warehouse_id = rs[0].warehouse_id || '';
					warehouse_name = rs[0].warehouse_name || '';
					util.store.commit(this,'setEditVo', {
						name:warehouse_name
					});
				}
			this.$store.state.global.eventVue.$emit('showPopCom', {
				_this: this,
				id: id,
				data: {
					fn: {
						sure: function(data) {
							util.showConfirm(_this, () => {
								let param = {
									hotel_id: id,
									warehouse_id:data.id
								};
								util.http.SR(_this, '/index/Product/addWarehouseUse', param, '添加成功', (rs) => {
									logic.list.refreshListData(_this);
								});
							},{content:'更换仓库将删除所有原仓库商品，是否确定更换？'});

						}
					},
					field: {
						bindModel: 44,
						bind_type: 0,
						title: '添加仓库至场景',
						name: 'id',
						bind_name_field:'name',
						fval:warehouse_id,
						needBind:1
					}
				},
				name: 'Jbind'
			});
		})

		},
    },
    computed: {
        ctl() {
            return this.$route.query.ctl;
        },
        is_admin() {
            return util.is_admin(this);
        },
    },
    watch: {},

    props: ['col', '_id', 'detail_info', 'wrapper_name'],
    created() {},
}
</script>
<style rel="stylesheet/less" lang="less">
</style>
